package com.helwen.utils;

import cn.hutool.json.JSONUtil;

import com.helwen.entity.UserDto;


import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder;

public class CurrentUserUtil {

    public static UserDto getCurrentUser(HttpServletRequest request){
        
            /*try{
                String token=request.getHeader(AuthConstant.JWT_TOKEN_HEADER);
                if(token!=null && !"".equals(token)){
                    String realToken = token.replace(AuthConstant.JWT_TOKEN_PREFIX, "");
                    JWSObject jwsObject = JWSObject.parse(realToken);
                    String userStr = jwsObject.getPayload().toString();
                    UserDto userDto = JSONUtil.toBean(userStr, UserDto.class);
                    return userDto;
                }else{
                    String userStr = request.getHeader(AuthConstant.USER_TOKEN_HEADER);
                    if(userStr!=null && !"".equals(userStr)){
                        String decode = URLDecoder.decode(userStr, "utf-8");
                        //String ss=URLDecoder.decode(decode, "utf-8");
                        UserDto userDto = JSONUtil.toBean(decode, UserDto.class);
                        return userDto;
                    }else {
                        String id = request.getHeader(AuthConstant.CURRENT_USER_ID);
                        String city = request.getHeader(AuthConstant.CURRENT_USER_CITY);
                        if(id!=null && !"".equals(id)){
                            UserDto userDto =new UserDto();
                            userDto.setId(Long.parseLong(id));
                            userDto.setTenantId(city);
                            return userDto;
                        }
                    }

                }

            }catch (Exception e){
                e.printStackTrace();
            }*/

        return null;
    }
}
